/*
 * @Author: 嘛的叭卡 xxxxxy_112@163.com
 * @Date: 2025-03-11 15:45:25
 * @LastEditors: 嘛的叭卡 xxxxxy_112@163.com
 * @LastEditTime: 2025-03-11 17:11:15
 * @FilePath: \government_map\vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import { resolve } from "node:path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";


// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd());

  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [VantResolver()],
      }),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      host: true,
      port: 3000,
      open: true,
    },
    build: {
      target: 'es2022', // 更新目标环境为 es2022 或更高版本
      outDir: "dist",
      assetsDir: "assets",
      sourcemap: command === "serve",
      // 生产环境移除console
      minify: "terser",
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    },
  };
});
